Collisions

A collision is a pair of two inputs which produce the same digest when hashed, i.e. .

When the input space is larger than the digest space (as is usually the case for hash functions), collisions are guaranteed to exist thanks to the pigeonhole principle - if you have 6 holes and 7 pigeons and you want to fit all pigeons into a hole, then at least one hole must contain more than one pigeon. However, collisions are the cause of many headaches and so we had to come up with ways to minimise them.

(First-) Preimage Resistance

Each output of a hash function can be obtained from multiple possible inputs (if, as usual, the output length is shorter than the input length). Preimage resistance means that given full knowledge of how works and a digest , it is very difficult to find any one of the inputs that hash to .

Definition: Preimage Resistance

A hash function has preimage resistance or is preimage resistant if for all efficient adversaries given a digest and full knowledge of the probability that can find an input such that is negligible, i.e.

Preimage resistant hash functions are also called one-way functions because it is very difficult to reverse the output back into one of the inputs that can be used to obtain it. In fact, it is impossible to find exactly the input that was hashed to the digest - even if we do find some such that , we can never be sure if , since there are multiple inputs which hash to the same digest.

The notion of preimage resistance is heavily relied on in the secure storage of passwords - when an adversary manages to get their hands on the hash of a password, we want to be sure that they cannot recover the actual password from it.

Second-Preimage Resistance

There is a stronger notion of preimage resistance which means that given one input , its digest and full knowledge of the hash function , it is very difficult to find one of the other inputs which produces the same hash .

Definition: Second-Preimage Resistance

A hash function has second-preimage resistance or is second-preimage resistant if for all efficient adversaries given an input , its digest and full knowledge of the internals of , the probability that can find another input such that is negligible, i.e.

Second-preimage resistance is stronger in the sense that second-preimage resistant hash functions are also first-preimage resistant.

Theorem: Second-Preimage Resistance → Preimage Resistance

Every hash function that is second-preimage resistant is also first-preimage resistant.

If an adversary who is given and cannot find an input such that , then they certainly cannot do it when given only .

Collision Resistance

The definition of collision resistance is particularly strong and states that if a hash function is collision resistant, then it should be very difficult to find any collisions in it.

Definition: Collision Resistance

A hash function provides collision resistance or is collision resistant if for all efficient collision finders , the probability that finds two inputs such that is negligible, i.e.

Definition Breakdown

An algorithm which tries to find a collision for a given hash function is called a collision finder. The hash function is considered to be collision resistant if there is no collision finder that can find a collision in it with significant probability.

It is not difficult to see that a collision resistant hash function is also second-preimage resistant and by extension first-preimage resistant. After all, if an adversary can find a colliding pair without any external help, such as an input and its digest , then it can certainly find a colliding pair with such help.

Theorem: Collision Resistance → Second-Preimage Resistance

Every collision resistant hash function is also second-preimage resistant.

Theorem: Collision Resistance → First-Preimage Resistance

Every collision resistant hash function is also first-preimage resistant, since it is second-preimage resistant.